package com.imooc.user.repository.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.imooc.user.provider.model.UserCenterGroupVo;
import com.imooc.user.repository.entity.TUserCenterGroup;
import com.imooc.user.repository.mapper.TUserCenterGroupMapper;
import com.imooc.user.repository.service.ITUserCenterGroupService;
import org.assertj.core.util.Lists;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.List;

/**
* <br>
* <b>功能：</b>群组表 服务实现类<br>
* <b>作者：</b>Tim<br>
* <b>日期：</b>2023<br>
*/
@Service
public class TUserCenterGroupServiceImpl extends ServiceImpl<TUserCenterGroupMapper, TUserCenterGroup> implements ITUserCenterGroupService {

    @Override
    public TUserCenterGroup getGroupByGroupId(String groupId) {
        LambdaQueryWrapper<TUserCenterGroup> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(TUserCenterGroup::getGroupId, groupId);
        return baseMapper.selectOne(queryWrapper);
    }

    @Override
    public List<TUserCenterGroup> getGroupByGroupIds(List<String> groupIds) {
        if (CollectionUtils.isEmpty(groupIds)){
            return Lists.newArrayList();
        }
        LambdaQueryWrapper<TUserCenterGroup> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.in(TUserCenterGroup::getGroupId, groupIds);
        return baseMapper.selectList(queryWrapper);
    }


    @Override
    public List<TUserCenterGroup> getGroupsBySchoolId(Long schoolId, List<Integer> groupTypes) {
        LambdaQueryWrapper<TUserCenterGroup> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(TUserCenterGroup::getParentId, schoolId);
        queryWrapper.in(TUserCenterGroup::getGroupType, groupTypes);
        List<TUserCenterGroup> tUserCenterGroups = baseMapper.selectList(queryWrapper);
        return tUserCenterGroups;
    }

    @Override
    public List<TUserCenterGroup> getGroupBySchoolId(Long schoolId, List<Integer> groupTypes) {
        LambdaQueryWrapper<TUserCenterGroup> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(TUserCenterGroup::getId, schoolId);
        queryWrapper.in(TUserCenterGroup::getGroupType, groupTypes);
        List<TUserCenterGroup> tUserCenterGroups = baseMapper.selectList(queryWrapper);
        return tUserCenterGroups;
    }

}
